package servlet;

import dao.UserDAO;
import dao.UserDAO1;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

@WebServlet(name = "userremove", value = "/user/remove")
public class UserRemoveServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        // 获取所有参数
        List<String> ids = new ArrayList<>(Arrays.asList(req.getParameterValues("id")));
        System.out.println("userIds: " + ids);
        UserDAO1 dao = new UserDAO1();
        for (String id : ids) {
            dao.delete(id);
            System.out.println("删除用户: " + id);
        }

        resp.sendRedirect("/Mall/user/list");
    }
}
